import 'package:flutter/widgets.dart';

/// Create by kyluzoi
/// Date: 2021-08-10
///
/// Description:

class SizeFit {
  static MediaQueryData? _mediaQueryData;
  static double? screenWidth;
  static double? screenHeight;
  static double? rpx;
  static double? px;
  static bool isInit = false;

  static void initialize(BuildContext context, {double standardWidth = 750}) {
    if (isInit) return;
    isInit = true;
    _mediaQueryData = MediaQuery.of(context);
    screenWidth = _mediaQueryData?.size.width;
    screenHeight = _mediaQueryData?.size.height;
    rpx = screenWidth! / standardWidth;
    px = screenWidth! / standardWidth * 2;
  }

  // 按照像素来设置
  static double setPx(double size) {
    return SizeFit.rpx! * size * 2;
  }

  // 按照rxp来设置
  static double setRpx(double size) {
    return SizeFit.rpx! * size;
  }
}
